package com.jic.product.controller.manage;


import com.jic.common.base.vo.RestResult;
import com.jic.manager.api.rest.ManagerStoreApi;
import com.jic.manager.response.MemMerchantInfoResponse;
import com.jic.product.manage.response.ProductDistributeResponse;
import com.jic.product.service.ProductDistributeService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by ZXK on 2020/1/9 11:04
 * 商品分发管理
 */
@RestController
@RequestMapping("productDistribute")
@Api(value = "商品分发", description = "商品分发", tags = "商品分发")
@Slf4j
public class ProductDistributeController {

    @Autowired
    private ProductDistributeService ProductDistributeService;

    @Resource
    ManagerStoreApi managerStoreApi;

    /*
     *
     *查询分发
     * */
    @ResponseBody
    @GetMapping(value = "/queryProductDistribute")
    public RestResult queryProductDistribute(Long productId) {
        List<MemMerchantInfoResponse> list = new ArrayList<>();
        try {
            List<Long> deptIds = ProductDistributeService.queryByProductId(productId);
            if (CollectionUtils.isNotEmpty(deptIds)) {
                list = managerStoreApi.getMerchantList(deptIds);
            }
        } catch (Exception e) {
            log.error("9999", e.getLocalizedMessage());
            return RestResult.error("9999", e.getLocalizedMessage());
        }
         return RestResult.success(list);
    }


    /**
     * 商家商品管理渠道分发列表查询
     *
     * @author: JackHe
     * @date: 2020/4/9 14:14
     */
    @ResponseBody
    @GetMapping(value = "/queryProductSource")
    public RestResult<List<ProductDistributeResponse>> queryProductSource(Long productId) {
        return ProductDistributeService.queryStoreIdByProductId(productId);
    }
}
